/**
 * Company : TIS.
 * Created By : Chatree Siangklom
 * Created On : Aug 21, 2013  11:31:25 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.database.services.impl
 * File Name : AGenCodeDaoServiceImpl.java
 * TODO
 */
package com.tis.database.services.impl;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tis.database.dao.AGenCodeDao;
import com.tis.database.entitys.AGenCode;
import com.tis.database.services.IAGenCodeDaoServices;

/**
 * @author Administrator
 *
 */
@Service
@Transactional(readOnly = true)
public class AGenCodeServicesImpl implements IAGenCodeDaoServices {
	
	private static final Logger log = LoggerFactory.getLogger(AGenCodeServicesImpl.class);
	
	@Autowired 
	private AGenCodeDao aGenCodeDao;

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#findById(java.lang.Integer)
	 */
	@Override
	public AGenCode findById(BigDecimal id)  throws HibernateException, Exception {
		return aGenCodeDao.findById(id);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#saveUpdate(com.tis.database.entitys.AGenCode)
	 */
	@Override
	@Transactional(readOnly = false)
	public AGenCode saveUpdate(AGenCode aGenCode) throws HibernateException, Exception{
		aGenCodeDao.saveOrUpdate(aGenCode);
		aGenCode = aGenCodeDao.findById(aGenCode.getPkId());
		return aGenCode;
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#saveUpdate(java.util.List)
	 */
	@Override
	@Transactional(readOnly = false)
	public void saveUpdate(List<AGenCode> aGenCodeList) throws HibernateException, Exception{
		aGenCodeDao.saveOrUpdate(aGenCodeList);		
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#save(com.tis.database.entitys.AGenCode)
	 */
	@Override
	@Transactional(readOnly = false)
	public AGenCode save(AGenCode aGenCode) throws HibernateException, Exception{
		aGenCodeDao.save(aGenCode);
		aGenCode = aGenCodeDao.findById(aGenCode.getPkId());
		return aGenCode;
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#save(java.util.List)
	 */
	@Override
	@Transactional(readOnly = false)
	public void save(List<AGenCode> aGenCodeList) throws HibernateException, Exception{
		aGenCodeDao.save(aGenCodeList);;
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#delete(com.tis.database.entitys.AGenCode)
	 */
	@Override
	@Transactional(readOnly = false)
	public void delete(AGenCode aGenCode) throws HibernateException, Exception{
		aGenCodeDao.delete(aGenCode);
	}

	 
	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#remove(com.tis.database.entitys.AGenCode)
	 */
	@Override
	@Transactional(readOnly = false)
	public void remove(AGenCode aGenCode) throws HibernateException, Exception{
		aGenCodeDao.remove(aGenCode);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#remove(java.util.List)
	 */
	@Override
	@Transactional(readOnly = false)
	public void remove(List<AGenCode> aGenCodeList) throws HibernateException, Exception{
		aGenCodeDao.remove(aGenCodeList);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#findAGenCodesByCode(java.lang.String)
	 */
	@Override
	public List<AGenCode> findAGenCodesByCode(String code) throws HibernateException, Exception{
		return aGenCodeDao.findByAGenCodeCode(code);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#findAGenCodesByName(java.lang.String)
	 */
	@Override
	public List<AGenCode> findAGenCodesByName(String name) throws HibernateException, Exception{
		return aGenCodeDao.findByAGenCodeName(name);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#findAlList()
	 */
	/**
	 * warning : low performance
	 */
	@Override
	public List<AGenCode> findAllList() throws HibernateException, Exception{
		return aGenCodeDao.findByAll(0);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#findInID(java.util.List)
	 */
	@Override
	public List<AGenCode> RefreshObject(List<AGenCode> aGenCodeList) throws HibernateException, Exception {
		return aGenCodeDao.RefreshObject(aGenCodeList);
	}

	/* (non-Javadoc)
	 * @see com.tis.database.services.AGenCodeDaoService#delete(java.util.List)
	 */
	@Override
	@Transactional(readOnly = false)
	public void delete(List<AGenCode> aGenCodeList) throws HibernateException, Exception {
		aGenCodeDao.delete(aGenCodeList);
	}
}
